package com.jiuqi.abc.model.web;

import com.jiuqi.abc.model.bean.DriverGroup;
import com.jiuqi.abc.model.service.ABCDriverGroupService;
import com.jiuqi.np.core.restapi.annotation.PermissionsResourceGroup;
import com.jiuqi.nvwa.sf.anno.Licence;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = {"abc模型动因分组管理"})
@RestController
@RequestMapping("abc/model/driverGroup")
@PermissionsResourceGroup("abc模型动因分组管理")
@Licence(module="com.jiuqi.abc.modelmanager", point="com.jiuqi.abc.function")
public class ABCDriverGroupController {

    @Autowired
    private ABCDriverGroupService abcDriverGroupService;

    @ApiOperation("根据 模型表主键 获取 动因分组集合")
    @GetMapping("list/{modelId}")
    public List<DriverGroup> getDriverGroupListByModelId(@PathVariable("modelId") String modelId) {
        return abcDriverGroupService.getDriverGroupListByModelId(modelId);
    }

    @ApiOperation("根据 模型表主键 获取 动因分组集合详细信息（包含动因、动因项、动因项公式）")
    @GetMapping("detailList/{modelId}")
    public List<DriverGroup> getDetailDriverGroupListByModelId(@PathVariable("modelId") String modelId) {
        return abcDriverGroupService.getDetailDriverGroupListByModelId(modelId);
    }

    @ApiOperation("添加动因分组")
    @PostMapping("add")
    public void addDriverGroup(@RequestBody DriverGroup driverGroup) {
        abcDriverGroupService.addDriverGroup(driverGroup);
    }

    @ApiOperation("编辑动因分组名称")
    @PostMapping("update")
    public DriverGroup updateDriverGroup(@RequestBody DriverGroup driverGroup) {
        abcDriverGroupService.modifyDriverGroup(driverGroup);
        return driverGroup;
    }

    @ApiOperation("删除单个动因分组")
    @GetMapping("delete/{key}")
    public void deleteDriverGroup(@PathVariable("key") String key) {
        abcDriverGroupService.deleteDriverGroup(key);
    }

    @ApiOperation("拖拽插入")
    @GetMapping("changeOrder/{modelId}/{dragIndex}/{targetIndex}")
    public void changeDriverGroupOrder(@PathVariable("modelId") String modelId,
                                       @PathVariable("dragIndex") int dragIndex,
                                       @PathVariable("targetIndex") int targetIndex) {
        abcDriverGroupService.changeDriverGroupOrder(modelId,dragIndex,targetIndex);
    }
}
